package com.example.example02;

import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;

import org.apache.hadoop.io.Writable;
/**
 * 1. 必须实现Writable接口
 * 2. 反序列化时，需要反射调用空参构造函数，所以必须有空参构造
 * 3. 重写序列化方法write与readFields方法
 * 4. 反序列化的字段顺序和序列化字段的顺序必须完全一致
 * 5. 方便展示结果数据，需要重写bean对象的toString()方法，可以自定义分隔符
 * 6. 如果自定义Bean对象需要放在Mapper输出KV中的K,则该对象还需实现Comparable接口
 */
public class SpeakBean implements Writable {
  // 这些属性字段
  private long selfDuration;
  private long thirdPartDuration;
  private long sumDuration;
  
  // 反序列化时，需要反射调用空参构造函数，所以必须有
  public SpeakBean() { }
  
  // 这个构造参数我们自己用
  public SpeakBean(long selfDuration,long thirdPartDuration,long sumDuration){
    this.setSelfDuration(selfDuration);
    this.setThirdPartDuration(thirdPartDuration);
    this.setSumDuration(sumDuration);
  }
  
  public void set(long selfDuration, long thirdPartDuration, long sumDuration) {
    this.setSelfDuration(selfDuration);
    this.setThirdPartDuration(thirdPartDuration);
    this.setSumDuration(sumDuration);
  }

  @Override
  public void readFields(DataInput in) throws IOException {
    this.selfDuration = in.readLong();
    this.thirdPartDuration = in.readLong();
    this.sumDuration = in.readLong();
  }

  @Override
  public void write(DataOutput out) throws IOException {
    out.writeLong(this.selfDuration);
    out.writeLong(this.thirdPartDuration);
    out.writeLong(this.sumDuration);
  }
  
  @Override
  public String toString() {
    return selfDuration + "\t" + thirdPartDuration + "\t" + sumDuration ;
  }
  
  // getter 、 setter
  public long getSumDuration() {
    return this.sumDuration;
  }

  public void setSumDuration(long sumDuration) {
    this.sumDuration = sumDuration;
  }

  public long getThirdPartDuration() {
    return this.thirdPartDuration;
  }

  public void setThirdPartDuration(long thirdPartDuration) {
    this.thirdPartDuration = thirdPartDuration;
  }

  public long getSelfDuration() {
    return this.selfDuration;
  }

  public void setSelfDuration(long selfDuration) {
    this.selfDuration = selfDuration;
  }
}